﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class OptionsCtrl : MonoBehaviour
{
    public InputField musicOffset;
    public InputField hitsoundVolume;
    public InputField playerName;
    public InputField dspBuffer;
    public Toggle useNativeAudio;
    public InputField noteSize;
    public InputField backgroundBrightness;
    public InputField resourcePath;

    void Start()
    {
        UpdateData();
        useNativeAudio.isOn = PlayerPrefs.GetInt("UseNativeAudio", 1) == 1;
    }

    public void ChangeData()
    {
        PlayerPrefs.SetFloat("NoteSize", float.Parse(noteSize.text));
        PlayerPrefs.SetFloat("HitSoundsVolume", float.Parse(hitsoundVolume.text));
        PlayerPrefs.SetFloat("MusicOffset", float.Parse(musicOffset.text));
        PlayerPrefs.SetFloat("BackgroundBrightness", float.Parse(backgroundBrightness.text));
        PlayerPrefs.SetInt("DspBuffer", int.Parse(dspBuffer.text));
        PlayerPrefs.SetString("ResourcesPath", resourcePath.text);
        PlayerPrefs.SetString("PlayerName", playerName.text);
        PlayerPrefs.SetInt("UseNativeAudio", useNativeAudio.isOn ? 1 : 0);
        UpdateData();
    }

    public void UpdateData()
    {
        noteSize.text = PlayerPrefs.GetFloat("NoteSize", 0.055f).ToString();
        hitsoundVolume.text = PlayerPrefs.GetFloat("HitSoundsVolume", 0.6f).ToString();
        musicOffset.text = PlayerPrefs.GetFloat("MusicOffset", 0f).ToString();
        backgroundBrightness.text = PlayerPrefs.GetFloat("BackgroundBrightness", 0.5f).ToString();
        dspBuffer.text = PlayerPrefs.GetInt("DspBuffer", 256).ToString();
        resourcePath.text = PlayerPrefs.GetString("ResourcesPath", Application.persistentDataPath + "/Tracks");
        playerName.text = PlayerPrefs.GetString("PlayerName", "Guest,#FF0000");
    }
}
